var contentPublicData;

/**
 * 首页
 */

function homeNav() {
    navSelected('#homeNavItem');
    contentHeadShow('.homeHead');
    clearContentTable();
    initHome();
}

/**
 * 首页导航初始化
 */
function initHome() {
    iniPublicData();
}

function iniPublicData() {
    $.ajax({
        async: false,
        cache: false,
        type: 'GET',
        datType: "json",
        accept: "application/json;charset=UTF-8",
        contentType: "application/json;charset=UTF-8",
        url: '/public',
        success: function (data) {
            contentPublicData = data._embedded.public;
            clearContentData();
            displayNoticeList(contentPublicData);
        },
        error: function (data) {
        }
    });
}

function displayNoticeList(data) {
    var contentDataDiv = $('#contentsData');
    data.forEach(function(item) {
        var noticeItem = $('<a href="#" class="list-group-item list-group-item-action"></a>');
        var nameElement = $('<h5 class="mb-1"></h5>').text(item.name);
        var textElement = $('<p class="mb-1"></p>').text(item.text);
        var timeElement = $('<small></small>').text(item.createTime);

        noticeItem.append(nameElement, textElement, timeElement);
        contentDataDiv.append(noticeItem);
    });
}

function clearContentData() {
    $('#contentsData').empty();
}